home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
misc
/
emu
/
ATUtilities.lha
/
ATUtilities
/
po.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-09-26
|
15KB
|
594 lines
/* ******************************************************************* */
/* ** ** */
/* ** ATUtilities Port Setup ** */
/* ** Copright (C) 1992-1994 by Thomas Dreibholz ** */
/* ** All rights reserved ** */
/* ** ** */
/* ******************************************************************* */
#include "janus.h"
#include "ATUtilities.h"
UBYTE *PortSetupPort="ATUtilities Port Setup";
UBYTE *PrefsName="AT:Prefs/PortSetup.prefs";
UBYTE *DefPrefsName="AT:Prefs/PortSetupDefault.prefs";
UBYTE *HelpName="AT:Help/PortSetup.help";
struct PortPrefs
{
UWORD LPT[4];
UWORD LPTTimeOut[4];
UWORD COM[4];
UWORD COMTimeOut[4];
};
struct PortPrefs PortPrefs;
struct PortPrefs DefPortPrefs=
{
0,0,0,0,
20,20,20,20,
0,0,0,0,
20,20,20,20
};
struct JanusBase *JanusBase;
struct Library *GfxBase;
struct Library *IntuitionBase;
struct Library *ATUtilitiesBase;
struct DualPortedMemory *dpm;
struct ExtSetupSig *ExtSetupSig;
struct Window *WindowPtr;
struct RastPort *rp;
struct CommMemory *jhbyte,*jhword;
struct JRemember *JRemember=NULL;
LONG JanusSignal;
LONG PortSignal;
ULONG JanusSignalMask;
ULONG PortSignalMask;
ULONG WaitSignalMask;
ULONG Signale;
BOOL defOkay=FALSE;
VOID HandleInt();
VOID ShowInfo();
VOID OpenAll();
VOID CloseAll();
BOOL EinstellungenAendern();
UWORD TimeOut();
UWORD Wahl();
struct MsgPort *Port;
/* Installationsroutine */
VOID main()
{
REGISTER UWORD i;
REGISTER BOOL bool;
register struct Task *task;
OpenAll();
bool=FALSE;
task=FindTask(NULL);
while(bool==FALSE)
{
Signale=Wait(WaitSignalMask);
if(Signale & PortSignalMask)
{
i=Received(Port);
switch(i)
{
case UTILITY_CALL:
bool=EinstellungenAendern();
break;
case UTILITY_QUIT:
DisplayBeep(NULL);
bool=TRUE;
break;
case UTILITY_INFO:
ShowInfo();
break;
case UTILITY_HELP:
Help(HelpName,0);
break;
}
}
if(Signale & JanusSignalMask)
{
HandleInt();
}
}
CloseAll();
}
/* PC-Befehle ausführen */
VOID HandleInt()
{
register struct FileHandle *fh;
switch(jhword->Arg1)
{
case 1:
DefPortPrefs.LPT[0]=jhword->Arg2;
DefPortPrefs.LPT[1]=jhword->Arg3;
DefPortPrefs.LPT[2]=jhword->Arg4;
DefPortPrefs.LPT[3]=jhword->Arg5;
jhword->Arg2=PortPrefs.LPT[0];
jhword->Arg3=PortPrefs.LPT[1];
jhword->Arg4=PortPrefs.LPT[2];
jhword->Arg5=PortPrefs.LPT[3];
break;
case 2:
DefPortPrefs.LPTTimeOut[0]=jhword->Arg2;
DefPortPrefs.LPTTimeOut[1]=jhword->Arg3;
DefPortPrefs.LPTTimeOut[2]=jhword->Arg4;
DefPortPrefs.LPTTimeOut[3]=jhword->Arg5;
jhword->Arg2=PortPrefs.LPTTimeOut[0];
jhword->Arg3=PortPrefs.LPTTimeOut[1];
jhword->Arg4=PortPrefs.LPTTimeOut[2];
jhword->Arg5=PortPrefs.LPTTimeOut[3];
break;
case 3:
DefPortPrefs.COM[0]=jhword->Arg2;
DefPortPrefs.COM[1]=jhword->Arg3;
DefPortPrefs.COM[2]=jhword->Arg4;
DefPortPrefs.COM[3]=jhword->Arg5;
jhword->Arg2=PortPrefs.COM[0];
jhword->Arg3=PortPrefs.COM[1];
jhword->Arg4=PortPrefs.COM[2];
jhword->Arg5=PortPrefs.COM[3];
break;
case 4:
DefPortPrefs.COMTimeOut[0]=jhword->Arg2;
DefPortPrefs.COMTimeOut[1]=jhword->Arg3;
DefPortPrefs.COMTimeOut[2]=jhword->Arg4;
DefPortPrefs.COMTimeOut[3]=jhword->Arg5;
jhword->Arg2=PortPrefs.COMTimeOut[0];
jhword->Arg3=PortPrefs.COMTimeOut[1];
jhword->Arg4=PortPrefs.COMTimeOut[2];
jhword->Arg5=PortPrefs.COMTimeOut[3];
break;
case 10:
if(defOkay==FALSE)
{
fh=Open(DefPrefsName,MODE_NEWFILE);
if(fh!=NULL)
{
Write(fh,&DefPortPrefs,sizeof(struct PortPrefs));
Close(fh);
}
defOkay=TRUE;
}
break;
}
SendJanusInt(30);
}
/* Installationsroutine */
VOID OpenAll()
{
REGISTER UWORD i;
register struct MsgPort *p;
register struct FileHandle *fh;
ATUtilitiesBase=OpenLibrary("at-utilities.library",0L);
if(ATUtilitiesBase==NULL)
{
printf("ERROR: Kann ATUtilities-Library nicht öffnen.\n");
CloseAll();
}
GfxBase=OpenLibrary("graphics.library",0L);
IntuitionBase=OpenLibrary("intuition.library",0L);
if((GfxBase==NULL)||(IntuitionBase==NULL))
{
CloseAll();
}
p=FindPort(PortSetupPort);
if(p!=NULL)
{
InfoRequest("ATUtilities Port Setup-Handler ist schon aktiv.");
CloseAll();
}
JanusBase=OpenLibrary("janus.library",0L);
if(JanusBase==NULL)
{
ErrorRequest(ERROR_JANUS);
CloseAll();
}
dpm=MakeWordPtr(JanusBase->ParameterRAM);
Port=CreatePort(PortSetupPort,0L);
if(Port==NULL)
{
ErrorRequest(ERROR_MPORT);
CloseAll();
}
fh=Open(DefPrefsName,MODE_OLDFILE);
if(fh!=NULL)
{
Read(fh,&DefPortPrefs,sizeof(struct PortPrefs));
Close(fh);
}
fh=Open(PrefsName,MODE_OLDFILE);
if(fh!=NULL)
{
Read(fh,&PortPrefs,sizeof(struct PortPrefs));
Close(fh);
}
else
{
CopyMem(&DefPortPrefs,&PortPrefs,sizeof(struct PortPrefs));
}
ExtSetupSig=CreatePublicHandler(30);
if(ExtSetupSig==NULL)
{
CloseAll();
}
jhword=ExtSetupSig->WordAccess;
jhbyte=ExtSetupSig->ByteAccess;
PortSignal=Port->mp_SigBit;
PortSignalMask=(1L<<PortSignal);
JanusSignal=ExtSetupSig->JanusSignal;
JanusSignalMask=ExtSetupSig->JanusSignalMask;
WaitSignalMask=PortSignalMask+JanusSignalMask;
ChangeTaskPri(5);
}
/* Programmende */
VOID CloseAll()
{
if(ExtSetupSig) DeletePublicHandler(ExtSetupSig);
if(Port) DeletePort(Port);
if(ATUtilitiesBase) CloseLibrary(ATUtilitiesBase);
if(GfxBase) CloseLibrary(GfxBase);
if(IntuitionBase) CloseLibrary(IntuitionBase);
if(JanusBase) CloseLibrary(JanusBase);
exit(0);
}
/* Einstellungsfenster */
BOOL EinstellungenAendern()
{
UBYTE tex[60];
REGISTER UWORD i,j,id;
REGISTER BOOL bool,ende;
REGISTER ULONG Class;
register struct Window *win;
register struct Gadget *gad;
register struct IntuiMessage *msg;
register struct FileHandle *fh;
register struct RastPort *rp;
register struct TextFont *opal;
bool=FALSE;
win=CreateStdWindow("ATUtilities - Port Setup Einstellungen",
75,75,450,95,GADGETUP|CLOSEWINDOW,
WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
if(win!=NULL)
{
rp=win->RPort;
opal=GetOpalFont();
SetFont(rp,opal);
CreateBoolGadget(win,10,15,155,12,"Einstellungen okay",1);
CreateBoolGadget(win,170,15,155,12,"Programm beenden",2);
CreateBoolGadget(win,335,15,50,12,"Info",3);
CreateBoolGadget(win,390,15,50,12,"Hilfe",4);
for(i=0;i<=3;i++)
{
if(PortPrefs.LPT[i]!=0)
sprintf(&tex,"LPT%ld: $%03lx",i+1,PortPrefs.LPT[i]);
else
sprintf(&tex,"LPT%ld: None",i+1);
CreateBoolGadget(win,10,35+(i*14),100,12,&tex,10+i);
sprintf(&tex,"T-Out: %ld",PortPrefs.LPTTimeOut[i]);
CreateBoolGadget(win,115,35+(i*14),100,12,&tex,20+i);
if(PortPrefs.COM[i]!=0)
sprintf(&tex,"COM%ld: $%03lx",i+1,PortPrefs.COM[i]);
else
sprintf(&tex,"COM%ld: None",i+1);
CreateBoolGadget(win,235,35+(i*14),100,12,&tex,30+i);
sprintf(&tex,"T-Out: %ld",PortPrefs.COMTimeOut[i]);
CreateBoolGadget(win,340,35+(i*14),100,12,&tex,40+i);
}
ende=FALSE;
while(ende==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
gad=msg->IAddress;
Class=msg->Class;
ReplyMsg(msg);
switch(Class)
{
case CLOSEWINDOW:
ende=TRUE;
break;
case GADGETUP:
id=gad->GadgetID;
switch(id)
{
case 1:
fh=Open(PrefsName,MODE_NEWFILE);
if(fh!=NULL)
{
Write(fh,&PortPrefs,sizeof(struct PortPrefs));
Close(fh);
}
ende=TRUE;
break;
case 2:
ende=TRUE; bool=TRUE;
break;
case 3:
ShowInfo();
break;
case 4:
Help(HelpName,0);
break;
default:
if(id<20)
{
j=id-10;
sprintf(&tex,"Adresse von LPT%ld festlegen",j+1);
PortPrefs.LPT[j]=Wahl(&tex,PortPrefs.LPT[j],DefPortPrefs.LPT[j]);
if(PortPrefs.LPT[j]!=0)
sprintf(&tex,"LPT%ld: $%03lx",j+1,PortPrefs.LPT[j]);
else
sprintf(&tex,"LPT%ld: None",j+1);
DrawCPTextBorder(win,10,35+(j*14),100,12,&tex);
}
else if(id<30)
{
j=id-20;
sprintf(&tex,"Time-Out von LPT%ld festlegen",j+1);
PortPrefs.LPTTimeOut[j]=TimeOut(&tex,PortPrefs.LPTTimeOut[j],
DefPortPrefs.LPTTimeOut[j]);
sprintf(&tex,"T-Out: %ld",PortPrefs.LPTTimeOut[j]);
DrawCPTextBorder(win,115,35+(j*14),100,12,&tex);
}
else if(id<40)
{
j=id-30;
sprintf(&tex,"Adresse von COM%ld festlegen",j+1);
PortPrefs.COM[j]=Wahl(&tex,PortPrefs.COM[j],DefPortPrefs.COM[j]);
if(PortPrefs.COM[j]!=0)
sprintf(&tex,"COM%ld: $%03lx",j+1,PortPrefs.COM[j]);
else
sprintf(&tex,"COM%ld: None",j+1);
DrawCPTextBorder(win,235,35+(j*14),100,12,&tex);
}
else if(id<50)
{
j=id-40;
sprintf(&tex,"Time-Out von COM%ld festlegen",j+1);
PortPrefs.COMTimeOut[j]=TimeOut(&tex,PortPrefs.COMTimeOut[j],
DefPortPrefs.COMTimeOut[j]);
sprintf(&tex,"T-Out: %ld",PortPrefs.COMTimeOut[j]);
DrawCPTextBorder(win,340,35+(j*14),100,12,&tex);
}
}
break;
}
}
DeleteStdWindow(win);
}
if(bool==TRUE) DisplayBeep(NULL);
return(bool);
}
/* Information */
VOID ShowInfo()
{
InformationBox("ATUtilities Port Setup - Information",
"$VER: Port Setup - Version 4.0",
"Copyright (C) 1992-1994 by",
"Thomas Dreibholz",
"All rights reserved.",
"AT:Icons/Utility");
}
/* Adresse ändern */
UWORD Wahl(titel,alt,def)
UBYTE *titel;
UWORD alt,def;
{
UBYTE str[40];
UBYTE cmd[10];
UBYTE tex[3];
UBYTE phase;
UWORD neu;
REGISTER UWORD i,j,k;
REGISTER BOOL ende;
REGISTER ULONG Class;
register struct Window *win;
register struct Gadget *gad;
register struct IntuiMessage *msg;
register struct RastPort *rp;
register struct TextFont *opal;
neu=alt;
win=CreateStdWindow(titel,75,75,450,95,GADGETUP|CLOSEWINDOW,
WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
if(win!=NULL)
{
rp=win->RPort;
opal=GetOpalFont();
SetFont(rp,opal);
CreateBoolGadget(win,10,15,115,12,"Okay",100);
CreateBoolGadget(win,130,15,115,12,"Abbruch",200);
sprintf(&str,"Original: $%03lx",def);
CreateBoolGadget(win,250,15,190,12,&str,300);
k=0; phase='0';
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
sprintf(&tex,"%c",phase);
CreateBoolGadget(win,10+(j*28),35+(i*13),26,12,&tex,k);
k++; phase++;
if(phase==':') phase='A';
}
}
k=0;
sprintf(&str,"Alte Portadresse: $%03lx",alt);
DrawNTextBorder(win,130,35,310,12,&str);
SelectStdFPen(rp);
WriteText(rp,145,58,"Bitte neue Portadresse eingeben,");
WriteText(rp,145,68,"$000 für keine Schnittstelle.");
sprintf(&str,"Neue Portadresse: $%03lx",neu);
DrawNTextBorder(win,130,74,310,12,&str);
phase=0;
ende=FALSE;
while(ende==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
gad=msg->IAddress;
Class=msg->Class;
ReplyMsg(msg);
switch(Class)
{
case CLOSEWINDOW:
neu=alt;
ende=TRUE;
break;
case GADGETUP:
i=gad->GadgetID;
switch(i)
{
case 100:
if(phase!=0) neu=alt;
ende=TRUE;
break;
case 200:
neu=alt;
ende=TRUE;
break;
case 300:
neu=def;
ende=TRUE;
break;
default:
j=i;
switch(phase)
{
case 0:
neu=j*256;
phase++;
sprintf(&cmd,"%01lx--",j);
break;
case 1:
neu=neu+(j*16);
phase++;
sprintf(&cmd,"%02lx-",neu/16);
break;
default:
neu=neu+j;
phase=0;
sprintf(&cmd,"%03lx",neu);
break;
}
sprintf(&str,"Neue Portadresse: $%s",&cmd);
DrawCNTextBorder(win,130,74,310,12,&str);
break;
}
break;
}
}
DeleteStdWindow(win);
}
return(neu);
}
/* TimeOut ändern */
UWORD TimeOut(titel,alt,def)
UBYTE *titel;
UWORD alt,def;
{
UBYTE str[30];
UBYTE *zahl;
UWORD neu;
REGISTER UWORD i,j;
REGISTER BOOL ende;
REGISTER ULONG Class;
register struct Window *win;
register struct Gadget *gad;
register struct IntuiMessage *msg;
register struct RastPort *rp;
register struct TextFont *opal;
neu=alt;
win=CreateStdWindow(titel,75,75,450,50,GADGETUP|CLOSEWINDOW,
WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE);
if(win!=NULL)
{
rp=win->RPort;
opal=GetOpalFont();
SetFont(rp,opal);
CreateBoolGadget(win,10,15,115,12,"Okay",100);
CreateBoolGadget(win,130,15,115,12,"Abbruch",200);
sprintf(&str,"Original: %ld",def);
CreateBoolGadget(win,250,15,190,12,&str,300);
SelectStdFPen(rp);
WriteText(rp,15,43,"Anzahl der Zähler für Time-Out:");
sprintf(&str,"%ld",alt);
zahl=CreateIntegerGadget(win,340,35,100,10,&str,4,400);
ende=FALSE;
while(ende==FALSE)
{
WaitPort(win->UserPort);
msg=GetMsg(win->UserPort);
gad=msg->IAddress;
Class=msg->Class;
ReplyMsg(msg);
switch(Class)
{
case CLOSEWINDOW:
neu=alt;
ende=TRUE;
break;
case GADGETUP:
i=gad->GadgetID;
switch(i)
{
case 100:
neu=atol(zahl);
if(neu>255) neu=255;
ende=TRUE;
break;
case 200:
neu=alt;
ende=TRUE;
break;
case 300:
neu=def;
ende=TRUE;
break;
}
break;
}
}
DeleteStdWindow(win);
}
return(neu);
}